define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user_watch/index' + location.search,
                    table: 'user_watch',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.nickname', title:'昵称'},
                        {field: 'deviceid', title: __('Deviceid')},
                        {field: 'notes', title: __('Notes')},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'operate',
                            title: __('Operate'),
                            table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'heartrate',
                                    text: __('心率'),
                                    icon: '',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    extend: 'data-area=\'["90%", "80%"]\'',
                                    url:"user/heartrate?deviceid={deviceid}",
                                },
                                {
                                    name: 'bloodpressure',
                                    text: __('血压'),
                                    classname: 'btn btn-xs btn-warning btn-dialog',
                                    extend: 'data-area=\'["90%", "80%"]\'',
                                    url:"user/bloodpressure?deviceid={deviceid}",
                                },
                                {
                                    name: 'bloodoxygen',
                                    text: __('血氧'),
                                    classname: 'btn btn-xs btn-danger btn-dialog',
                                    extend: 'data-area=\'["80%", "70%"]\'',
                                    url:"user/bloodoxygen?deviceid={deviceid}",
                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
